<%@ page contentType="text/html; charset=utf-8"%>
<%@ include file="/global/jsp-header.jsp"%>
<c:set var="deptQueryVisable" value="${d:accessUri('/dept/dept-query.do',pageContext.request) }"></c:set>
<c:set var="deptAddVisable" value="${d:accessUri('/dept/dept-add.do',pageContext.request) }"></c:set>
<c:set var="deptDeleteVisable" value="${d:accessUri('/dept/dept-delete.do',pageContext.request) }"></c:set>
<c:set var="deptEditVisable" value="${d:accessUri('/dept/dept-edit.do',pageContext.request) }"></c:set>
<!DOCTYPE HTML>
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html">
		<title>部门管理</title>
		<%@ include file="/global/html-header.jsp"%>
		<script type="text/javascript">
		$(function() {
			$(".myform").idealforms();
			<c:if test="${deptQueryVisable}">
			$("#myform").submit();
			</c:if>
			common.validator("myform");
			common.initDialog("message-dialog");
			common.initDialog("delete-dialog");
			common.initDelDialogMsg("确定要删除此部门？");
			<c:if test="${deptAddVisable}">
			$("#addDept").on("click",function(){
				$("#addorupdate-dialog").wijdialog({ width: 500, height: 440, contentUrl: '/dept/dept-addorupdate.do?operationType=insert', autoOpen: true,modal : true,title:"新增部门" });
			});
			</c:if>
			
			$("#delete-dialog").wijdialog({
	            autoOpen: false,
	            resizable: false,
	            height: 200,
	            width: 320,
	            modal: true,
	            title:'删除部门',
	            buttons: {
	                "确定": function () {
	                	if(!$("#delete-dialog").attr("operaterId")){
	                		return false;
	                	}
	                	<c:if test="${deptDeleteVisable}">
	                	var delDeptId=$("#delete-dialog").attr("operaterId");
	                	$.ajax({   
	                		type: "POST",  
	                		url: "/dept/dept-delete.do",  
	                		data: ({"dept.deptId":delDeptId}), 
	                		success: function(msg){    
	                			if(msg=="success"){
	                				$("#msgcontent").html("部门删除成功！");
	                				$("#queryResultIframe").contents().find("tr[deptId='"+delDeptId+"']'").remove();
	                			}else if(msg=="deptvested"){
	                				$("#msgcontent").html("部门删除失败(有组别归属)！");
	                			}else{
	                				$("#msgcontent").html("部门删除失败！");
	                			}
	                			common.tipWithAutoClose("message-dialog");
	                		} 
	                	});
	                    $(this).wijdialog("close");
	                    </c:if>
	                },
	                "取消": function () {
	                    $(this).wijdialog("close");
	                }
	            }
	        });
		});
		//删除部门窗口弹出
		function deleteDivOpen(deptId){
			$('#delete-dialog').wijdialog('open');
			$('#delete-dialog').attr("operaterId",deptId);
		}
		<c:if test="${deptEditVisable}">
		function editDeptTip(msg){
			$("#msgcontent").html(msg);
			common.tipWithAutoClose("message-dialog");
		}
		
		function editDivOpen(deptId){
			$("#addorupdate-dialog").wijdialog({ width: 500, height: 440, contentUrl: '/dept/dept-addorupdate.do?operationType=update&dept.deptId='+deptId, autoOpen: true,modal : true,title:"编辑部门" });
		}
		</c:if>
		function closeDialog(){
			$("#addorupdate-dialog").wijdialog('close');
		}
		</script>
	</head>
	<body>
		<div class="container ">
			<div class="content">
				<form action="/dept/dept-query.do" name="myform" class="myform"
					id="myform" target="queryResultIframe" method="post">
					<div>
						<label class="required">
							部门编号:
						</label>
						<input type="text" size="40" name="dept.deptId" class="digits" />
					</div>
					<div>
						<label class="required">
							部门名称:
						</label>
						<input type="text" size="40" name="dept.deptName" />
					</div>
					<div>
						<label class="required">
							部门职能:
						</label>
						<input type="text" size="40" name="dept.ability" class="digits" />
					</div>
					<div>
						<label>
							&nbsp;
						</label>
						<c:if test="${deptQueryVisable}">
						<input type="submit" value="提交" />
						<input type="reset" value="重置" />
						</c:if>
						<c:if test="${deptAddVisable}">
						<input type="button" id="addDept" value="新增"/>
						<em class="ideal-button" style="visibility:hidden;"></em>
						</c:if>
					</div>
				</form>
			</div>
			<div class="content hide" id="queryResult">
				<iframe class="queryResultIframe" name="queryResultIframe"
					id="queryResultIframe" src="about:blank" style="width: 97%;"
					frameborder="0" scrolling="no"></iframe>
			</div>
		</div>
		<%@ include file="/global/common-dialog.jsp" %>
	</body>
</html>